﻿
    using Maticsoft.BLL;
    using Maticsoft.DBUtility;
    using Maticsoft.Model;
    using System;
    using System.Data;
    using System.Web.UI.HtmlControls;
    using Utils;

    public partial class subscribe : FBasePage
    {

        protected string cityhtml = string.Empty;
        protected string curcityname = string.Empty;
        protected string useremail = string.Empty;

        protected override void OnLoad(EventArgs e)
        {
            string str;
            int @int;
            string str2;
            Maticsoft.BLL.Mailer mailer;
            Maticsoft.Model.Mailer mailer2;
            base.OnLoad(e);
            if (base.CurrentCity != null)
            {
                this.curcityname = base.CurrentCity.Id.ToString();
            }
            DataTable options = DbHelperSQL.SelectByFilter("id,name", "zone='city'", "Display desc", "category");
            this.cityhtml = HtmlHelper.AppendSelectControl("", "city_id", "f-city", options, "name", "id", this.curcityname);
            if (base.CurrentCity != null)
            {
            }
            if (base.ASUser != null)
            {
                this.useremail = base.ASUser.Email;
            }
            if ((base.Request.HttpMethod == "POST") && (base.Request["buttontype"] == "订阅"))
            {
                str = Helper.GetString(base.Request["head_email"], string.Empty);
                if (str != string.Empty)
                {
                    if (DbHelperSQL.SelectByFilter("*", "email='" + str + "'", "id asc", "mailer").Rows.Count == 0)
                    {
                        @int = Helper.GetInt(base.Request["cityid"], 0);
                        str2 = Guid.NewGuid().ToString();
                        mailer = new Maticsoft.BLL.Mailer();
                        mailer2 = new Maticsoft.Model.Mailer();
                        mailer2.Secret = str2;
                        mailer2.City_id = @int;
                        mailer2.Email = str;
                        mailer.Add(mailer2);
                    }
                    base.SetSuccess("邮件订阅成功");
                    return;
                }
                this.SetError("邮件地址不能为空");
            }
            if ((base.Request.HttpMethod == "POST") && (base.Request["buttontype"] == "订 阅"))
            {
                str = Helper.GetString(base.Request["left_email"], string.Empty);
                if (str != string.Empty)
                {
                    if (DbHelperSQL.SelectByFilter("*", "email='" + str + "'", "id asc", "mailer").Rows.Count == 0)
                    {
                        @int = Helper.GetInt(base.Request["cityid"], 0);
                        str2 = Guid.NewGuid().ToString();
                        mailer = new Maticsoft.BLL.Mailer();
                        mailer2 = new Maticsoft.Model.Mailer();
                        mailer2.Secret = str2;
                        mailer2.City_id = @int;
                        mailer2.Email = base.Request["left_email"];
                        mailer.Add(mailer2);
                    }
                    base.SetSuccess("邮件订阅成功");
                }
                else
                {
                    this.SetError("邮件地址不能为空");
                }
            }
            if ((base.Request.HttpMethod == "POST") && (base.Request["buttontype"] == "订  阅"))
            {
                str = Helper.GetString(base.Request["sub_email"], string.Empty);
                if (str != string.Empty)
                {
                    if (DbHelperSQL.SelectByFilter("*", "email='" + str + "'", "id asc", "mailer").Rows.Count == 0)
                    {
                        @int = Helper.GetInt(base.Request["city_id"], 0);
                        str2 = Guid.NewGuid().ToString();
                        mailer = new Maticsoft.BLL.Mailer();
                        mailer2 = new Maticsoft.Model.Mailer();
                        mailer2.Secret = str2;
                        mailer2.City_id = @int;
                        mailer2.Email = str;
                        mailer.Add(mailer2);
                    }
                    base.SetSuccess("邮件订阅成功");
                }
                else
                {
                    this.SetError("邮件地址不能为空");
                }
            }
            if ((base.Request.QueryString["email"] != null) && (base.Request.QueryString["email"] != ""))
            {
                str = Helper.GetString(base.Request.QueryString["email"], string.Empty);
                if (str != string.Empty)
                {
                    if (DbHelperSQL.SelectByFilter("*", "email='" + str + "'", "id asc", "mailer").Rows.Count == 0)
                    {
                        @int = Helper.GetInt(this.curcityname, 0);
                        str2 = Guid.NewGuid().ToString();
                        mailer = new Maticsoft.BLL.Mailer();
                        mailer2 = new Maticsoft.Model.Mailer();
                        mailer2.Secret = str2;
                        mailer2.City_id = @int;
                        mailer2.Email = str;
                        mailer.Add(mailer2);
                    }
                    base.SetSuccess("邮件订阅成功");
                }
                else
                {
                    this.SetError("邮件地址不能为空");
                }
            }
        }
    }


